{% extends "base.html" %}
{% block html_header %}
	<script type="text/javascript"><!-- 
	$(document).ready(function(){
		$('#calc_btn').click(calc_cocomo);
		$('#export_img').click(export_cocomo);
	})
	
	function export_cocomo() {
		var mode = $("input:radio[@name='calc_mode']:checked").val();
		var num  = jQuery.trim($("#num").val());

		if (mode && num != "") {
			var url = "/cocomo/export"
	                + "?calc_mode=" + mode
	                + "&num="       + num;
	
			window.open(url,'_blank');		
		} else {
			alert("入力項目に誤りがあります。");	
		}
	}
	
	function calc_cocomo() {
		var url = "/cocomo/calc"

		var data = new Object();
		data['calc_mode'] = $("input:radio[@name='calc_mode']:checked").val();
		data['num'] = jQuery.trim($("#num").val());

		error_msg();
		processing_msg(PROCESSING_MSG);

		$.getJSON(url, data, 
			function (json) {
				if (json.error) {
					error_msg(json.error);
				} else {
					numfield_format("#kdsi",json.kdsi);
					numfield_format("#kdsi",json.kdsi);
					numfield_format("#effort",json.effort);
					numfield_format("#tdev",json.tdev);
					numfield_format("#fsp",json.fsp);
					numfield_format("#prod",json.prod);
					numfield_format("#plan_requirements",json.plan_requirements);
					numfield_format("#product_design",json.product_design);
					numfield_format("#detailed_design",json.detailed_design);
					numfield_format("#code_unit_test",json.code_unit_test);
					numfield_format("#integration_test",json.integration_test);
					numfield_format("#total",json.total);
	
					for (var i=0; i< json.phase_plan_requirements.length; i++) {
						numfield_format("#phase_plan_requirements_" + i,json.phase_plan_requirements[i]);
						numfield_format("#phase_product_design_" + i,json.phase_product_design[i]);
						numfield_format("#phase_programming_" + i,json.phase_programming[i]);
						numfield_format("#phase_integration_test_" + i,json.phase_integration_test[i]);
						numfield_format("#phase_total_" + i,json.phase_total[i]);
					}
				}
				processing_msg();
			}
		);
	}
	function numfield_format(key, num_data) {
		$(key).text(num_data).format({format:"#,###.00",locale:"jp"}).addClass("num-field");
	}
	//--></script>
	<title></title>
{% endblock %}
{% block content %}
	<h1>COCOMO による工数計算 <a href="http://www.amazon.co.jp/dp/4798107204?tag=typea09-22&link_code=as3&creativeASIN=4798107204&creative=3999&camp=767" target="_blank" title="この本を元に作成しています"><img src="/images/book_open.png" border="0"></a></h1>
	<p style="color:green">プログラムサイズまたは、工数を選択し値を入力、計算ボタンを押します。</p> 
	<input type="radio" name="calc_mode" value="kdsi"/>プログラムサイズ(KLOC)
	<input type="radio" name="calc_mode" value="effort"/>工数(PM)
	<input type="text" id="num" maxlength="10" size="10"/>
	<input type="button" id="calc_btn" value="計算"/>
	
	<h3>COCOMO計算式 <img src='/images/icon_xls.gif' id="export_img" border='0' title="Excelへ出力します"></h3>
	<table width="400px;">
		<col width="*"/>
		<col width="50%"/>
		<tr>
			<th>プログラムサイズ(KLOC)</th>
			<td id='kdsi'></td>
		</tr>  
		<tr>
			<th>工数(PM)</th>
			<td id='effort'></td>
		</tr>
		<tr>
			<th>開発期間(M)</th>
			<td id='tdev'></td>
		</tr>
		<tr>
			<th>開発要員(P)</th>
			<td id='fsp'></td>
		</tr>
		<tr>
			<th>生産性(KLOC/PM)</th>
			<td id='prod'></td>
		</tr>
	</table>	
	
	<h3>工数の局面への分布 </h3>
	<table width="400px;">
		<col width="*"/>
		<col width="50%"/>
		<tr>
			<th>計画と要件定義 </th>
			<td id="plan_requirements">  </td>
		</tr>
		<tr>
			<th>製品設計</th>
			<td id="product_design"></td>
		</tr>
		<tr>
			<th>詳細設計</th>
			<td id="detailed_design"></td>
		</tr>
		<tr>
			<th>プログラミングと単体テスト</th>
			<td id="code_unit_test"></td>
		</tr>
		<tr>
			<th>統合とテスト</th>
			<td id="integration_test"></td>
		</tr>
		<tr>
			<th>合計</th>
			<td id="total"></td>
		</tr>
	</table>
	
	<h3>活動の局面ごとの分布</h3>  
	<table width="780px;">
		<col width="*"/>  
	   	<col width="14%"/>  
	   	<col width="14%"/>
	   	<col width="12%"/>
	   	<col width="12%"/>
	   	<col width="14%"/>
	   	<col width="14%"/>
	   	<tr>
	    	<th rowspan="2">局面</th>
	    	<th rowspan="2">計画と要件定義</th>
			<th rowspan="2">製品設計</th>
			<th colspan="2">プログラミング</th>
			<th rowspan="2">統合とテスト</th>
			<th rowspan="2">合計</th>
		</tr>
		<tr>
			<th>詳細設計</th>
			<th>プログラミングと単体テスト</th>
		</tr>
		{% for title in phase_title %}
		<tr>
			<th>{{title}}</th>
			<td id="phase_plan_requirements_{{forloop.counter0}}"></td>
			<td id="phase_product_design_{{forloop.counter0}}"></td>
			<td colspan="2" id="phase_programming_{{forloop.counter0}}"></td>
			<td id="phase_integration_test_{{forloop.counter0}}"></td>
			<td id="phase_total_{{forloop.counter0}}"></td>
		</tr>
		{% endfor %}
	</table>
{% endblock %}